<template>
<h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">{{item}}</li>
  </ul>
<ul>
  <li v-for="p in Arr">{{p}}</li>
</ul>
<table>
  <tr>
    <td>序号</td>
    <td>标题</td>
    <td>价格</td>
    <td>库存</td>
    <td>操作</td>
  </tr>
  <tr v-for="(item,index) in Arr">
  <td>{{index+1}}</td>
  <td>{{item.title}}</td>
  <td>{{item.price}}</td>
  <td>{{item.num}}</td>
  <td><button @click="del(index)">删除</button></td>
  </tr>
</table>
</template>
<script setup>
import {ref} from "vue";
const Arr=ref([
  {title:'苹果',price:50,num:20},
  {title:'香蕉',price:150,num:50},
  {title:'桃子',price:350,num:60},
  {title:'西瓜',price:80,num:80},
])
const del=(index)=>{
  if (confirm('您确认要删除吗?')){
    Arr.value.splice(index,1);
  }
}
</script>

<style scoped>

</style>